package com.lsy.weizhi2.activity;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.config.Constants;
import com.lsy.weizhi2.config.MyHeight;
import com.lsy.weizhi2.customview.MyListView;
import com.lsy.weizhi2.mybase.BaseApp;
import com.lsy.weizhi2.mybase.MyBaseActivity;

public class ConnectService extends MyBaseActivity {
    private com.lsy.weizhi2.mybase.MyTitleView mConnect_title;
    private TextView mWengti;
    private MyListView mWengtilist;
    private View mDivider;
    private TextView mKefu;
    private TextView mQq_kefu_1;
    private TextView mQq_kefu_2;
    private View mDivider2;
    private TextView mKefu2;
    private TextView mGf_kefu;
    private Context context;
    private int xx;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_connect_service);
        context = ConnectService.this;
        bindViews();
    }

    private void bindViews() {

        mConnect_title = (com.lsy.weizhi2.mybase.MyTitleView) findViewById(R.id.connect_title);
        mWengti = (TextView) findViewById(R.id.wengti);
        mWengtilist = (MyListView) findViewById(R.id.wengtilist);
        mDivider = findViewById(R.id.divider);
        mKefu = (TextView) findViewById(R.id.kefu);
        mQq_kefu_1 = (TextView) findViewById(R.id.qq_kefu_1);
        mQq_kefu_2 = (TextView) findViewById(R.id.qq_kefu_2);
        mDivider2 = findViewById(R.id.divider2);
        mKefu2 = (TextView) findViewById(R.id.kefu2);
        mGf_kefu = (TextView) findViewById(R.id.gf_kefu);
    }

    @Override
    protected void onStart() {
        super.onStart();
        WentiAdapter wentiAdapter = new WentiAdapter();
        mWengtilist.setAdapter(wentiAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        xx = 0;
        ViewTreeObserver vto = mConnect_title.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (xx < 1) {
                    xx++;
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mConnect_title.getLayoutParams());
                            params.height = MyHeight.ACTIONBAR + MyHeight.MyTitleHeight;
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                mConnect_title.setLayoutParams(params);
                            }
                        }
                    });
                }
            }
        });
    }

    class WentiAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return Constants.Kefu.length;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            Holder holder;
            if (view == null) {
                holder = new Holder();
                view = View.inflate(context, R.layout.wenti_text_item, null);
                holder.wenti_text_item = (TextView) view.findViewById(R.id.textView);
                view.setTag(holder);
            } else {
                holder = (Holder) view.getTag();
            }

            holder.wenti_text_item.setText(Constants.Kefu[i]);

            return view;
        }

        class Holder {
            TextView wenti_text_item;
        }
    }
}
